package xdu.lz.stage2_design_pattern.chapter10_up_down_context_pattern;


public class ExecutionTask implements Runnable {

    //模拟从数据库拿出数据的操作
    private QueryFromDBAction queryFromDBAction = new QueryFromDBAction();
    //模拟从互联网拿数据
    private QueryFromHttpAction httpAction = new QueryFromHttpAction();

    @Override
    public void run() {
        //先查name，在通过name查cardId，这是一种上下文资源。当资源多的时候，需要传递很多参数。
        //把资源和对应的线程一一绑定即可消灭这种情况。并且可以保证线程安全
        final Context context = new Context();
        //take data from db and set the data into context Obj
        queryFromDBAction.execute(context);
        System.out.println("the name query successful");
        //take data from web and set data into context Obj
        httpAction.execute(context);
        System.out.println("the cardId query successful");
        System.out.println("name :"+context.getName() + "  card id:"+context.getCardId());
    }
}
